<template>
	<view class="">
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="资讯详情" :autoBack="true">
			</u-navbar>
		</view>
		<view class="con-body wrap">
			<view style="width:94%;padding-left:3%">
				<view style="font-weight: bold;font-size: 32rpx;color:#333">{{article.title}}</view>
				<view class="u-flex u-row-between" style="margin:20rpx 0;">
					<view style="font-size: 24rpx;color:#999;"><text style="margin-right:20rpx">{{article.author}}</text>{{article.time}}</view>
					<view class="" style="right:20rpx;top:0;font-size: 26rpx;">
						<view class="dis_inl_blo" style="font-size: 26;color:#666;margin-left:30rpx;" @click="like(article.id)">{{article.like}}
							<view class="dis_inl_blo"><u-icon :name="likeIcon" :color="likeColor" size="18"></u-icon></view>
						</view>
						<view class="dis_inl_blo" style="font-size: 26;color:#666;margin-left:20rpx;">{{article.comment}}
							<view class="dis_inl_blo">
								<u-icon name="chat" color="#666" size="17"></u-icon>
							</view>
						</view>
					</view>
				</view>
				
				
				<view class="u-content">
					<u-parse :content="article.content"></u-parse>
				</view>
				<view>
					<u-line></u-line>
				</view>
				<view style="background-color: #FFFFFF;">
					<u-form-item style="width: 100%;">
						<u-input placeholder="请输入评论内容" v-model="commentValue">
							<template slot="suffix">
								<u-button @tap="newsComment" text="评论" type="primary" size="mini"></u-button>
							</template>
						</u-input>
					</u-form-item>
				</view>
			</view>
			<view style="background-color: #f8f8f8;width:100%;height:20rpx;"></view>
			<u-toast ref="uToast"></u-toast>
			<view class="fixed_bottom" v-if="istoreplay" style="border-top:1rpx solid #eee;">
				<view style="padding-left: 30rpx; padding-right: 30rpx; background-color: #FFFFFF;">
					<u-form-item style="width: 100%;">
						<u-input :placeholder="placeholder" :focus="focus" v-model="replycomment">
							<template slot="suffix">
								<u-button @tap="toreplycomment" text="发送" type="primary" size="mini"></u-button>
							</template>
						</u-input>
					</u-form-item>
				</view>
			</view>
			
			<view class="all-reply" style="margin-bottom:30rpx;">
				<view class="all-reply-top">全部评论（{{ allReply }}）</view>
				<u-empty :show="showEmpty" mode="comment" icon="http://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
				<view class="item" v-for="(item, index) in commentList" :key="index">
					<view class="comment">
						<view class="top">
							<view class="left">
								<view class="heart-photo"><image :src="item.avatar" mode=""></image></view>
								<view class="user-info">
									<view class="name">{{ item.username }}</view>
									<view class="date">{{ item.time }}</view>
								</view>
							</view>
							<view class="right">
								<view class="user-info t_c" @click="tolikecomment(item.id)">
									<view class="date">{{ index + 1 }}楼</view>
								</view>
							</view>
						</view>
						<view class="content" style="margin-left: 75rpx;margin-top:10rpx;" @click="totworeplay(item)">{{ item.content }}</view>
						<view class="reply-box" style="padding-left:30rpx;">
							
							<view class="all-reply" @tap="toAllReply" v-if="item.allReply != 0">
								<view class="all-reply-top">全部回复（{{ item.allReply }}）</view>
								<view class="item" v-for="(item1, index1) in item.reply" :key="index1">
									<view class="comment">
										<view class="top">
											<view class="left">
												<view class="heart-photo"><image :src="item1.avatar" mode=""></image></view>
												<view class="user-info">
													<view class="name">{{ item1.username }}</view>
													<view class="date">{{ item1.time }}</view>
												</view>
											</view>
										</view>
										<view class="content" style="margin-left: 75rpx;margin-top:10rpx;" @click="totworeplay(item1)">{{ item1.content }}</view>
										<view class="reply-box">
										
											<view class="all-reply" style="border:none;margin:0;" v-if="item1.allReply != 0">
												<!-- <view class="all-reply-top">全部回复（{{ item1.allReply }}）</view> -->
												<view class="item" v-for="(item2, index2) in item1.reply" :key="index2">
													<view class="comment" style="padding:30rpx 0 0;">
														<view class="top">
															<view class="left">
																<view class="heart-photo">
																	<image :src="item2.avatar" mode=""></image>
																</view>
																<view class="user-info">
																	<view class="name">{{ item2.username }}
																		<view class="dis_inl_blo"><u-icon name="play-right-fill" size="12" color="#999"></u-icon></view>
																		{{ item1.username }}
																	</view>
																	<view class="date">{{ item2.time }}</view>
																</view>
															</view>
														</view>
														<view class="content" style="margin-left: 75rpx;margin-top:10rpx;" >{{ item2.content }}</view>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getNewDetail,getNewsComment,newsComment,newsLike,likeDynamic
	} from "@/service/communitService.js";
	export default {
		data() {
			return {
				title: '精选文章',
				article: {},
				showEmpty:false,
				commentValue:'',
				commentList:[],
				allReply:0,
				istoreplay:false,
				focus:false  ,//回复聚焦
				placeholder:'请输入回复内容',
				replyid:0,
				replycomment:'',
				gid:0,
				likeIcon:'thumb-up',
				likeColor:'#666'
			};
		},
		onLoad(options) {
			// console.log(options);
			this.gid=options.id;
			getNewDetail({
				id: options.id
			}).then(this.getNewDetail);
			getNewsComment({
				gid: options.id
			}).then(this.getComment);
		},
		methods: {
			getNewDetail(e) {
				// console.log(e);
				if (e.code == 200) {
					this.title = e.result.title;
					this.article = e.result;
					this.allReply=e.result.comment
				} else {

				}
			},
			// 评论列表
			getComment(e) {
				if (e.code == 200) {
					this.commentList = e.result.data;
					// this.allReply = e.result.total;
					this.showEmpty=false
				}else{
					this.showEmpty=true
				}
			},
			newsComment() {
				newsComment({
					gid: this.gid,
					content: this.commentValue
				}).then(res => {
					if (res.code == 200) {
						this.$refs.uToast.show({
							message: res.msg,
							type: 'success'
						});
						this.commentList = res.result.data.data;
						this.allReply = res.result.data.total;
						this.showEmpty=false
					} else {
						this.$refs.uToast.show({
							message: res.msg,
							type: 'warning'
						});
					}
				});
			
				this.commentValue = '';
			},
			totworeplay(item){
				this.istoreplay=true;
				this.focus=true;
				this.replyid=item.id;
				this.placeholder='@'+item.username
			},
			toreplycomment(){
				newsComment({
					id: this.replyid,
					gid:this.gid,
					content: this.replycomment
				}).then(res => {
					if (res.code == 200) {
						this.$refs.uToast.show({
							message: res.msg,
							type: 'success'
						});
						this.commentList = res.result.data.data;
						this.allReply = res.result.data.total;
						this.replyid=0;
						this.istoreplay=false
					} else {
						this.$refs.uToast.show({
							message: res.msg,
							type: 'warning'
						});
					}
				});
				
				this.replycomment = '';
			},
			like(id) {
				newsLike({
					gid: id
				}).then(res => {
					this.likeColor="red";
					this.likeIcon="thumb-up-fill";
					if (res.code == 200) {
						this.article.like += 1;
						
						this.$refs.uToast.show({
			
							type: 'success',
							title: '成功',
							message: res.msg
						})
					} else {
						this.$refs.uToast.show({
			
							type: 'error',
							title: '失败',
							message: res.msg
						})
					}
				});
			},
			
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.u-content {
		margin-top: 20rpx;
		padding: 0rpx 20rpx 40rpx;
	}
	.fixed_bottom{
		position: fixed;
		bottom:0;
		left:0;
		width:100%;
		z-index:999;
	}
	.comment {
		padding: 30rpx;
		font-size: 32rpx;
		background-color: #ffffff;
	
		.top {
			display: flex;
			justify-content: space-between;
		}
	
		.left {
			display: flex;
	
			.heart-photo {
				image {
					width: 64rpx;
					height: 64rpx;
					border-radius: 50%;
					background-color: #f2f2f2;
				}
			}
	
			.user-info {
				margin-left: 10rpx;
	
				.name {
					color: #008987;
					font-size: 28rpx;
					margin-bottom: 4rpx;
				}
	
				.date {
					font-size: 20rpx;
					color: $u-light-color;
				}
			}
		}
	
		.right {
			display: flex;
			font-size: 20rpx;
			align-items: center;
			color: #9a9a9a;
	
			.like {
				margin-left: 6rpx;
			}
	
			.num {
				font-size: 26rpx;
				color: #9a9a9a;
			}
		}
	
		.highlight {
			color: #008987;
	
			.num {
				color: #008987;
			}
		}
	}
	
	.all-reply {
		margin-top: 10rpx;
		padding-top: 20rpx;
		background-color: #ffffff;
	
		.all-reply-top {
			margin-left: 20rpx;
			padding-left: 20rpx;
			border-left: solid 4rpx #008987;
			font-size: 30rpx;
			font-weight: bold;
		}
	
		.item {
			// border-bottom: solid 2rpx $u-border-color;
		}
		.bottom{
			background-color: #FFFFFF;
		}
	
		.reply {
			padding: 20rpx;
			background-color: rgb(242, 242, 242);
			border-radius: 12rpx;
			margin: 10rpx 0;
	
			.username {
				font-size: 24rpx;
				color: #7a7a7a;
			}
		}
	}
	
	.album {
		@include flex;
		padding: 20rpx;
		margin-top: 1px;
		align-items: flex-start;
		background-color: #FFFFFF;
		border-radius: 10rpx;
	
	
		&__avatar {
			padding: 5rpx;
			border-radius: 3rpx;
		}
	
		&__content {
			margin-left: 20rpx;
			flex: 1;
		}
	}
</style>
